package com.example.demo.core;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Page {
    /**
     * 数据总量
     */
    private int total;
    /**
     * 第几页
     */
    private int pageNum;
    /**
     * 这页数据多少
     */
    private int pageSize;
    /**
     * 总共几个数据
     */
    private int pages;
    /**
     * 分好的list
     */
    private List listPage;

    <T> Page(List<T> list,int page,int limit)
    {
        total=list.size();
        List<List<T>> taoList=new LinkedList<>();
        List<T> list1=new LinkedList<>();
        for (int i=1;i<=list.size();i++)
        {
            list1.add(list.get(i-1));
            if (i%(limit)==0)
            {
                taoList.add(new LinkedList<>(list1));
                list1.clear();
            }
        }
        if(!list1.isEmpty())
        {
            taoList.add(new LinkedList<>(list1));
        }
        listPage=taoList.get(page-1);
        pages=taoList.size();
        pageNum=page;
        pageSize=listPage.size();
        total=list.size();
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List getListPage() {
        return listPage;
    }

    public void setListPage(List listPage) {
        this.listPage = listPage;
    }
}
